﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElectrosLTD.Models;
using System.Web.Security;

namespace ElectrosLTD.Controllers
{
    public class AuthenticationController : Controller
    {
        //
        // GET: /Authentication/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Authenticate()
        {
            return View(new LoginModel());
        }
        
        [HttpPost]
        public ActionResult Authenticate(LoginModel lm)
        {
            {
                if (new UserServ.UserWCFClient().UserAuthentication(lm.username, lm.password) == true)
                {
                    Common.User u = new UserServ.UserWCFClient().GetUserByUsername(lm.username);
                    //int num = new ProductHistoryServ.
                    FormsAuthentication.RedirectFromLoginPage(lm.username, true);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    return RedirectToAction("Authenticate", "Authentication");
                }
            }
        }
    }
}
